import request from '@/utils/request'
// import qs from 'qs'

// 白名单过滤

// 获取白名单列表
export function getWhiteList (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/getWhiteList',
    method: 'post',
    data
  })
}

// 获取白名单信息
export function getWhiteInfo (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/getWhiteInfo',
    method: 'post',
    data
  })
}

// 修改白名单
export function editWhitelist (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/editWhitelist',
    method: 'post',
    data
  })
}

// 添加白名单
export function addWhitelist (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/addWhitelist',
    method: 'post',
    data
  })
}

// 删除白名单
export function delWhiteList (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/delWhiteList',
    method: 'post',
    data
  })
}

// 添加白名单规则
export function addRule (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/addRule',
    method: 'post',
    data
  })
}

// 编辑规则
export function editRule (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/editRule',
    method: 'post',
    data
  })
}

// 删除规则
export function delRule (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/delRule',
    method: 'post',
    data
  })
}

// 白名单过滤--添加白名单自定义协议规则
export function addWhitelistCustomRule (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/addWhitelistCustomRule',
    method: 'post',
    data
  })
}

// 白名单过滤--编辑白名单自定义协议规则
export function editWhitelistCustomRule (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/editWhitelistCustomRule',
    method: 'post',
    data
  })
}

// 白名单过滤--删除白名单自定义协议规则特征
export function delContent (params) {
  var data = fromData(params)
  return request({
    url: '/whitelist/delContent',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
